package validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator(value = "validators.pwd")
public class UserPwdValidator implements Validator {
	
	public UserPwdValidator() {
		
	}
	
	@Override
	public void validate(FacesContext context, UIComponent component,
			Object value) throws ValidatorException {
		
		UIInput passwordField = (UIInput) component.getAttributes().get("confirmPwd");
		String password = (String) passwordField.getSubmittedValue();
		
		if(!(value.toString().equals(password))){
			FacesMessage msg =
					new FacesMessage("user password validation failed.",
							"User password Validation failed, Password and Confirm Password should match");
							msg.setSeverity(FacesMessage.SEVERITY_ERROR);
					throw new ValidatorException(msg); }}
}
